package com.jinke.uang.http;

import com.jinke.uang.base.BaseObserable;
import com.jinke.uang.interfaces.ICommonView;

import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

/**
 * 作者：Song Shuyu
 * 时间：2019/4/9 16:30
 * package is com.jinke.uang.mvp
 */
public class ModelUtils {
    public static <T> void ModelUtils(Observable<T> observable, final ICommonView view, final int
            apiType, final String listType, Object... t) {
        observable.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserable() {
            @Override
            protected void onBaseNext(Object value) {
                view.showResponse(apiType, listType, value);
            }

            @Override
            protected void onBaseError(Throwable e) {
//                e.printStackTrace();
//                //在这里做全局的错误处理
//                if (e instanceof ConnectException || e instanceof SocketTimeoutException || e
//                        instanceof TimeoutException) {
//                    //网络错误
//                    onError(e);
//                } else if (e instanceof ResultException) {
//                    //自定义的ResultException
//                    //由于返回200,300返回格式不统一的问题，自定义GsonResponseBodyConverter凡是300的直接抛异常
//                    onError(((ResultException) e).getErrCode());
//                    System.out.println("---------errorCode------->" + ((ResultException) e)
//                            .getErrCode());
//                }
                view.showError(e);
            }
        });
    }
}

